<%-- 
    Document   : showimage
    Created on : Nov 5, 2012, 12:27:07 PM
    Author     : mruiz
--%>


<%@page import="org.apache.commons.io.FilenameUtils"%>
<%@page import="org.apache.commons.io.FileUtils"%>
<%@page import="com.gr.uth.homework3injsp.XMLManager"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <link rel="stylesheet" href="resources/showimage_style.css" type="text/css"/>
    </head>

    <body>

        <%
            String img = request.getParameter("img");
            String imgName = img.substring(0, img.lastIndexOf('.')); //without extensions
            XMLManager man = new XMLManager(application.getRealPath("WEB-INF/classes/xml_files/").replace('\\', '/') + "/" + imgName + ".xml");

            String[] elements = man.getElements();

            String w = elements[0];
            String h = elements[1];

            String rotation = "0";

            if (request.getParameter("height") != null || request.getParameter("width") != null || request.getParameter("rotation") != null) {

                h = (String) request.getParameter("height");
                w = (String) request.getParameter("width");
                if (request.getParameter("save") != null) {
                    man.updateXML(w, h, "Description N/A");
                }
                rotation = request.getParameter("rotation");

            }




        %>
        <div id="imm">
            <img src='./image/<%= img%>' height="<%=h%>px" width="<%=w%>px" style="transform: rotate(<%=rotation%>deg);
                 -moz-transform: rotate(<%=rotation%>deg);
                 -webkit-transform: rotate(<%=rotation%>deg);" />
        </div>    



        <div id="stylized" class="myform">
            <form action="showimage.jsp" method="GET">

                <label>Height:
                </label>
                <input name="height" type="text" value="<%=h%>" size="4"/>

                <label>Width:
                </label>
                <input name="width" type="text" value="<%=w%>" size="4"/>
                <input name="img" type="hidden" value="<%=img%>"/>
                <label>Rotate:
                </label>
                <input name="rotation" type="text" value="<%=rotation%>" size="3"/> deg.
                <input  style="width: 55px; float:left;" type="submit" value="Preview"/>
                <input  style="width: 55px; float:left;" name="save" type="submit" value="Save"/>

                <div class="spacer"></div>

            </form>
            <form action="index.jsp" method="GET">
                <input style="width: 65px; float:right;" name="mod_candeled" type="submit" value="Cancel" onclick="window.close();"/>
                <input style="width: 55px; float:right;" name="finish" type="submit" value="Finish" onclick="window.close();"/>
        </div>
    </form> 


    <% if (request.getParameter("save") != null) {
    %> <center><b style="color:#31B404;"> Changes saved</b></center><% }%>

</div>













</body>

</html>
